import { request } from "./utils";

// 查询所有类别
export function listAllCategory() {
  return request({
    url: "/category/listAll",
    method: "get"
  });
}

// 根据id查询产品
export function getCategoryById(categoryId: number) {
  return request({
    url: "/category/" + categoryId,
    method: "get"
  });
}

// 新增类别
export function addCategory(data: CategoryForm) {
  return request({
    url: "/category",
    method: "post",
    data: data
  });
}

// 修改类别
export function updateCategory(data: CategoryForm) {
  return request({
    url: "/category",
    method: "put",
    data: data
  });
}

// 删除类别
export function deleteCategory(categoryId: number) {
  return request({
    url: "/category/" + categoryId,
    method: "delete"
  });
}

interface CategoryDTO {
  categoryId: number;
  categoryName: string;
}

interface CategoryForm {
  categoryId?: number;
  categoryName?: string;
}

export type { CategoryDTO, CategoryForm };

/** 
 * pure-admin风格api

import { http } from "@/utils/http";
import type { AjaxResult } from "./types";
import { baseUrlApi } from "./utils";

export const listAllCategory = () => {
  return http.request<AjaxResult>("get", baseUrlApi("/category/listAll"));
};

export const getCategoryById = (categoryId: number) => {
  return http.request<AjaxResult>("get", baseUrlApi("/category/" + categoryId));
};

export const addCategory = (data: CategoryForm) => {
  return http.request<AjaxResult>("post", baseUrlApi("/category"), { data });
};

export const updateCategory = (data: CategoryForm) => {
  return http.request<AjaxResult>("put", baseUrlApi("/category"), { data });
};

export const deleteCategory = (categoryId: number) => {
  return http.request<AjaxResult>(
    "delete",
    baseUrlApi("/category/" + categoryId)
  );
};

 */
